package com.example.a66666.yuejian.Fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a66666.yuejian.Adapter.ActivityAdapter;
import com.example.a66666.yuejian.Adapter.MasterAdapter;
import com.example.a66666.yuejian.Bean.ActivityBean;
import com.example.a66666.yuejian.Bean.MasterBean;
import com.example.a66666.yuejian.Listener.RetrofitListener;
import com.example.a66666.yuejian.Loader.GlideImageLoader;
import com.example.a66666.yuejian.Model.UserModel;
import com.example.a66666.yuejian.R;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MasterFragment extends Fragment {

    private Banner banner;
    private ArrayList<String> listPath;
    private RecyclerView recyclerView;
    private UserModel userModel;
    private RetrofitListener<List<MasterBean>> listener;
    private LinearLayoutManager linearLayoutManager;
    private MasterAdapter masterAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.fragment_master,container,false);
        masterAdapter=new MasterAdapter();
        recyclerView=(RecyclerView)view.findViewById(R.id.masterRecyclerView);
        linearLayoutManager=new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(masterAdapter);
        initBanner(view);
        listener=new RetrofitListener<List<MasterBean>>() {
            @Override
            public void onSuccess(List<MasterBean> list) {
                masterAdapter.setData(list);
            }

            @Override
            public void onFail(String msg) {

            }
        };
        userModel=new UserModel();
        userModel.getAllMaser(listener);
        return view;
    }

    public void initBanner(View view){
        banner=(Banner)view.findViewById(R.id.masterBanner);
        listPath=new ArrayList<>();
        listPath.add("http://10.0.2.2/yuejian/public/static/masterLBT/1.jpg");
        listPath.add("http://10.0.2.2/yuejian/public/static/masterLBT/2.jpg");
        listPath.add("http://10.0.2.2/yuejian/public/static/masterLBT/3.jpg");
        listPath.add("http://10.0.2.2/yuejian/public/static/masterLBT/4.jpg");
        banner.setBannerStyle(BannerConfig.NUM_INDICATOR);
        banner.setImageLoader(new GlideImageLoader());
        banner.setImages(listPath);
        banner.setBannerAnimation(Transformer.DepthPage);
        banner.setDelayTime(2000);
        banner.setIndicatorGravity(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
        banner.start();
    }

}
